Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional JSON schema generation #516

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

afnanenayet
Copy link

Allow users to optionally derive JSON schemas using structs from this crate if they include schemars. This will allow consumers of this library to generate JSON schemas from structs that include structs created in this crate.

Optionally derive JSON schema information with the `schemars` library
@kvark
Copy link
Collaborator

kvark commented Sep 2, 2020

Thank you for making this PR!

I honestly haven't worked with JSON schemas in Rust. And I don't know what the established conventions are, so it's hard to tell if schemars would be needed in cgmath.
Given that cgmath is fairly low-supported atm, I'm curious to see if other libraries (with better support and stuffing) investigated their part. Did nalgebra, glam, and whatever, came to any conclusion wrt schemars integration?

@afnanenayet
Copy link
Author

It doesn't seem like either of the libraries mentioned have dealt with schema generation yet, at least not that I was able to find.

My use case is that I'm serializing structs that have Vector3 as a field, and I want to derive the JSON schema for those structs, and I can't do that unless every underlying struct also derives the schema.

@kvark
Copy link
Collaborator

kvark commented Sep 3, 2020

What are the stability guarantees for schemars? Would it work if the struct has fields serialized by different versions of this crate?

@afnanenayet
Copy link
Author

I'm actually not entirely sure, the documentation says this:

One of the main aims of this library is compatibility with Serde. Any generated schema should match how serde_json would serialize/deserialize to/from JSON.

serde_json and serde seem incredibly stable, so if this is piggybacking off of that, then I think this shouldn't have issues. I'll try to dig around the schemars source and see what's going on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants